home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / maplay-1.2 / synthesis_filter.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-04  |  3.0 KB  |  96 lines

  1. /*
  2.  *  @(#) synthesis_filter.h 1.8, last edit: 6/15/94 16:52:00
  3.  *  @(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)
  4.  *  @(#) Berlin University of Technology
  5.  *
  6.  *  This program is free software; you can redistribute it and/or modify
  7.  *  it under the terms of the GNU General Public License as published by
  8.  *  the Free Software Foundation; either version 2 of the License, or
  9.  *  (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public License
  17.  *  along with this program; if not, write to the Free Software
  18.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #ifndef SYNTHESIS_FILTER_H
  22. #define SYNTHESIS_FILTER_H
  23.  
  24. #include <iostream.h>
  25. #include "all.h"
  26. #include "obuffer.h"
  27.  
  28.  
  29. // A class for the synthesis filter bank:
  30. // This class does a fast downsampling from 32, 44.1 or 48 kHz to 8 kHz, if ULAW is defined.
  31. // Frequencies above 4 kHz are removed by ignoring higher subbands.
  32. class SynthesisFilter
  33. {
  34.   static const real d[512];
  35.   real v1[512], v2[512];
  36.   real *actual_v;            // v1 or v2
  37.   uint32 actual_write_pos;        // 0-15
  38.  
  39. #ifdef ULAW
  40.   uint32 offset1, offset2;        // number of samples to skip
  41.   uint32 remaining_offset;        // number of samples still to skip when entering
  42.                     // compute_pcm_samples() next time
  43.   uint32 highest_subband;        // highest subband to use, e.g. 7 for 32 kHz to 8 kHz conversion
  44. #endif
  45.   real     samples[32];            // 32 new subband samples
  46.  
  47.   uint32 channel;
  48.   real     scalefactor;
  49.   uint32 range_violations;
  50.   real     max_violation;
  51.   uint32 written_samples;
  52.  
  53.   void compute_new_v (void);
  54.   void compute_pcm_samples (Obuffer *);
  55.  
  56. public:
  57. #ifdef ULAW
  58.     SynthesisFilter (uint32 channelnumber, e_sample_frequency frequency,
  59.              real scalefactor = 32768.0);
  60.       // frequency specifies the sample rate of the stream.
  61. #else
  62.     SynthesisFilter (uint32 channelnumber, real scalefactor = 32768.0);
  63. #endif
  64.       // the scalefactor scales the calculated float pcm samples to short values
  65.       // (raw pcm samples are in [-1.0, 1.0], if no violations occur)
  66.  
  67.   void    input_sample (real sample, uint32 subbandnumber)
  68.   {
  69. #ifdef DEBUG
  70.     if (subbandnumber > 31)
  71.     {
  72.       cerr << "SynthesisFilter::input_sample(): illegal subbandnumber!\n";
  73.       exit (1);
  74.     }
  75. #endif
  76. #ifdef ULAW
  77.     if (subbandnumber <= highest_subband)
  78.       samples[subbandnumber] = sample;
  79. #else
  80.     samples[subbandnumber] = sample;
  81. #endif
  82.   };
  83.   void    calculate_pcm_samples (Obuffer *);
  84.     // calculate 32 PCM samples and put the into the Obuffer-object
  85.  
  86.   uint32 violations (void) { return range_violations; }
  87.   real     hardest_violation (void) { return max_violation; }
  88.   uint32 recommended_scalefactor (void) { return (uint32)(32768.0 / max_violation); }
  89.   real     seconds_played (uint32 frequency)
  90.   {
  91.     return (real)written_samples / (real)frequency;
  92.   }
  93. };
  94.  
  95. #endif
  96.